package com.liit.controller.weixin.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

import cn.liit.weixin.message.process.receive.ReceiveProcessorManager;
import cn.liit.weixin.message.type.EventType;
import cn.liit.weixin.message.type.ReqMessageType;

import com.liit.controller.weixin.process.MenuClickProcess;
import com.liit.controller.weixin.process.ScanMsgProcess;
import com.liit.controller.weixin.process.SubscribeMsgProcess;
import com.liit.controller.weixin.process.UnsupportedMsgProcess;

/**
 * 用于项目启动时注册微信消息处理器
 * 
 * @author 博奇
 * @version 1.0
 * @date 2016年1月3号
 */
@WebListener
public class WeixinListener implements ServletContextListener {

	/**
	 * Default constructor.
	 */
	public WeixinListener() {
	}

	/**
	 * @see ServletContextListener#contextInitialized(ServletContextEvent)
	 */
	public void contextInitialized(ServletContextEvent sce) {
		ReceiveProcessorManager.registerMsgProcessor(new SubscribeMsgProcess(ReqMessageType.REQ_MESSAGE_TYPE_EVENT.getType(), EventType.EVENT_TYPE_SUBSCRIBE.getType()));
		// ReceiveProcessorManager.registerMsgProcessor(new
		// TextMsgProcess(ReqMessageType.REQ_MESSAGE_TYPE_TEXT.getType(),
		// null));
		ReceiveProcessorManager.registerMsgProcessor(new ScanMsgProcess(ReqMessageType.REQ_MESSAGE_TYPE_EVENT.getType(), EventType.EVENT_TYPE_SCAN.getType()));
		ReceiveProcessorManager.registerMsgProcessor(new MenuClickProcess(ReqMessageType.REQ_MESSAGE_TYPE_EVENT.getType(), EventType.EVENT_TYPE_CLICK.getType()));
		ReceiveProcessorManager.registerMsgProcessor(new UnsupportedMsgProcess(ReceiveProcessorManager.UNSUPPORTED_MES_TYPE, null));
	}

	/**
	 * @see ServletContextListener#contextDestroyed(ServletContextEvent)
	 */
	public void contextDestroyed(ServletContextEvent sce) {
	}

}
